#include <iostream>
#include <algorithm>
using namespace std;
const int N = 100010;

int a[N];

int main()
{
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i)
    {
        cin >> a[i];
    }
    int ret = a[0];
    int sum = a[0];
    for (int i = 1; i < n; ++i)
    {
        if (sum >= 0)
        {
            sum += a[i];
        }
        else
        {
            sum = a[i];
        }
        ret = max(sum, ret);
    }
    cout << ret;
    return 0;
}